package bookstore.service;

import java.util.ArrayList;
import java.util.List;

import bookstore.domain.Book;
import bookstore.domain.Order;

public class GuestImpl implements Guest{
	Host host;              
	private List<Book> cart;
	
	public GuestImpl(Host host){
		this.host = host;
		this.cart = new ArrayList<Book>();
	}	

	public List<Book> buyList(){
		return host.stockList();
	};
	
	public boolean buy(int code){
		return cart.add(host.stockView(code));
	};	
	
	public List<Book> cartList(){
		return cart;
	};
	
	public boolean cartDel(int code){
		boolean isOK = false;
		for(int i=0;i<cart.size();i++)
			if(cart.get(i).getCode() == code) {
				if(cart.remove(i)!=null) isOK=true;				
				break;
			}
		return isOK;
	};
	
	public boolean cartPay(){
		boolean isOK = false;
		for(Book book:cart)
			isOK = host.sellAdd(new Order(book));
		cart.clear();
		return isOK;
	}	
	
	public List<Order> orderList(){
		return host.sellList();
	};
	
	public boolean orderCancel(int orderCode){
		return host.sellCancel(orderCode);
	};
}
